/**
 * 详情对话框
 */
var HxCollectingCenterInfoDlg = {
    data: {
        oldStockPort: "",
        stockPort: "",
        oldLocation: "",
        location: "",
    }
};

layui.use(['form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //获取详情信息，填充表单
    var stockPort =  Feng.getUrlParam("stockPort");
    $('#oldStockPort').val(stockPort.split("-")[1]);
    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        debugger;
        var ajax = new $ax(Feng.ctxPath + "/hxCollectingCenter/zhuanyi", function (data) {
            if(data.success){
                Feng.success("更新成功！");
                parent.location.reload();
                var Index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(Index);
            }else{
                Feng.error("更新失败！" + data.message)
            }
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //转移后通道
    form.on('select(stockPort)', function(data){
        //获取选择的单位名称
        let stockPort = $("#stockPort").val();
        //通过ajax获取商品信息
        $.ajax({
            url:Feng.ctxPath + "/hxCollectionLocation/findLocation?stockPort="+stockPort,
            cache: false,
            dataType:"json",
            success:function(data){
                if (data) {
                    $("#location").empty();
                    $("#location").append(new Option( "转移后位置", ""));// 下拉菜单里添加元素
                    data.forEach(row => {
                        $("#location").append(new Option( row.location, row.location));// 下拉菜单里添加元素
                    });
                    form.render("select");
                }
            }
        })
    });

    //返回按钮
    $("#backupPage").click(function () {
        var Index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(Index);
    });

});